//背包与魔法
#include <iostream>
#include <algorithm>

using namespace std;
#define int long long
const int N = 2010 , M = 10010;
int w[N] , v[N];//重量  价值
int dp[M][2];
int n , m , k;

signed main()
{
    cin >> n >> m >> k;
    for(int i = 1;i <= n;i ++)
    {
        cin >> w[i] >> v[i];
    }

    for(int i = 1;i <= n;i ++)
    {
        for(int j = m;j >= w[i];j --)
        {
            dp[j][0] = max(dp[j][0] , dp[j-w[i]][0] + v[i]);
            if(w[i] + k <= j)
            {
                dp[j][1] = max(max(dp[j][1],dp[j-w[i]][1] + v[i]) , dp[j-(w[i]+k)][0] + v[i] * 2);

            }
        }
    }
    cout << max(dp[m][1] , dp[m][0]) << endl;
    return 0;
}